Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't let the authorization header be empty #1373

Merged
merged 3 commits into from
Oct 25, 2016
Merged

Conversation

vbfox
Copy link
Contributor

@vbfox vbfox commented Oct 22, 2016

Summary

This PR is aimed at solving problems with @types (And I guess other public scopes) that can be seen in #825 and #1260 where even with the latest version yarn fails to restore packages where npm succeed. The case is specific to enterprise caches as the yarn or npm default repositories aren't affected.

In my case I had the problem and tested the resolution on ProGet ( http://inedo.com/proget ) configured with an NPM connector..

The issue is that always-auth is assumed for scoped packages, and always-auth forces the creation of an authorization: http header, even when no authentication can be found. The header is created empty in this case. As ProGet is an ASP.Net application and this platform consider an empty authorization header to be something that can never be met, it refuses the connection.

This PR doesn't change the behavior of always-auth being assumed for scoped packages but it remove the empty header if no authentication can be found.

Test plan

  • I ran yarn to restore packages in a previously non-working repository and checked that It worked, creating the lock file and was usable after. Tested yarn add with a new packages in @types
  • I tested the same commands while targeting the default repository instead of the cache to ensure that it worked.

I don't have access to a repository that require authentication for scoped packages but the change is minimal and doesn't affect any case where authentication was sent before so it shouldn't affect them (Also npm doesn't send the header in such cases)

@@ -177,7 +180,7 @@ export default class NpmRegistry extends Registry {
}
}

return '';
return undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this return an empty string please, we should ensure types are monomorphic if we can. An empty string will still evaluate the branch added above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 My first change completely ignored flowtype and changed only this line. I didn't realize after having changed the code calling the method that the change there wasn't even necessary anymore.

vbfox added 3 commits October 24, 2016 16:32
It create problems with some servers like ProGet when used as a nuget
cache.

It's most likely the source of yarnpkg#825 and yarnpkg#1260
@@ -58,7 +58,10 @@ export default class NpmRegistry extends Registry {

const headers = {};
if (this.token || (alwaysAuth && requestUrl.startsWith(registry))) {
headers.authorization = this.getAuth(pathname);
const authorization = this.getAuth(pathname);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we consider adding test coverage here via a unit test?

@sebmck sebmck merged commit 716503f into yarnpkg:master Oct 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants